package org.gap.jseed.annotation;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

import org.gap.registry.Registry;

public class FactoryMethodHandler implements InvocationHandler{
	Object instance;
	
	@Override
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		if (instance == null) {
			synchronized (this) {	
				Class<?> type = method.getReturnType();
				instance = Registry.get(type);
				if (instance == null && !type.isPrimitive()) {
					instance = type.newInstance();
				} else {
					
				}
			}
		}
		return instance;
	}
	
}
